/**
 * Created by ROGSTAR on 2016/11/7.
 */
require.config(window.jshead);
require(['jquery','layer','navigator'], function($,layer) {
    layer.config({
        path: '/js/layer/'
    });
    //登录
    $('#login').bind('click',function(){
        var phone=$('#phone').val();
        var password=$('#password').val();
        if(phone==""){
            layer.tips("请先输入11位手机号",'#phone');
            return;
        }
        if (!/^[1][3,4,5,7,8][0-9]{9}$/.exec(phone)) {
            layer.tips("请输入正确的手机号",'#phone');
            return;
        }
        if(password==""){
            layer.tips("密码不能为空",'#password');
            return;
        }
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        $.ajax({
            type: "POST",
            url: "/login/passwordLogin",
            data: {
                mobile:phone,
                password:password
            },
            dataType: "json",
            success: function (data) {
                layer.close(index)
                if(data.result=='success'){
                    if($.cookie('the_cookie') && $.cookie('the_cookie')!='null'){
                        window.location.href=$.cookie('the_cookie');
                        $.cookie('the_cookie',null);
                    }else{
                        window.location.href="/user/assets";
                    }
                }else{
                    if(data.messageText){
                        layer.tips(data.messageText,'#login');
                    }else{
                        layer.tips('登录失败','#login');
                    }
                }
            }
        });
    });
    //用户名输入后可点击删除
    $("#phone").bind("input propertychange",function(){
        var phone =$('#phone').val();
        var userDel = $(".login_input_wrap .user_del");
        if(phone){
            userDel.css({"display":"block"});
            userDel.bind("click", function (){
                $('#phone').val("");
                userDel.css({"display":"none"});
            })
        }else{
            userDel.css({"display":"none"});
        }
    })
    $(".login-content").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#login').click();
        }
    });

});